//
//  NavigationView.m
//  youtuyibao
//
//  Created by 吴宇 on 13-12-30.
//  Copyright (c) 2013年 youtu. All rights reserved.
//

#import "OANavigationView.h"

@implementation OANavigationView
@synthesize title;
@synthesize delegate;
@synthesize right;
@synthesize left;
@synthesize rightLabel;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled=YES;

        self.backgroundColor=RGBColor(40, 119, 193, 1);
        [self buildView];
    }
    return self;
}


- (void)setleftBtn:(NSString *)lImg andlD:(NSString*)ldImag
          rightBtn:(NSString *)rImg andrD:(NSString*)rDImag title:(NSString *)content
{
       if ([lImg length] != 0){
        [left setBackgroundImage:[UIImage imagefileNamed:lImg] forState:UIControlStateNormal];
        [left setBackgroundImage:[UIImage imagefileNamed:ldImag] forState:UIControlStateHighlighted];
    }
    else
    {
        left.hidden = YES;
    }
    if ([rImg length] != 0)
    {
        [right setBackgroundImage:[UIImage imagefileNamed:rImg] forState:UIControlStateNormal];
        [right setBackgroundImage:[UIImage imagefileNamed:rDImag] forState:UIControlStateHighlighted];
    }
    else
        right.hidden = YES;
    
    if ([content length] != 0)
        title.text = content;
    else
        title.hidden = YES;
    
}
- (void)setOpaques:(BOOL)opaques
{
    if (opaques) {
        self.image=[UIImage new];
        self.title.backgroundColor=[UIColor clearColor];

    }
    else
    {
        
    }
}
- (void)buildView
{
    left = [UIButton buttonWithType:UIButtonTypeCustom];
    [left addTarget:self action:@selector(leftButton) forControlEvents:UIControlEventTouchUpInside];
    right = [UIButton buttonWithType:UIButtonTypeCustom];
    [right addTarget:self action:@selector(rightButton) forControlEvents:UIControlEventTouchUpInside];
    
    title = [[UILabel alloc] init];
    title.userInteractionEnabled=YES;
    title.backgroundColor = [UIColor clearColor];
    title.textAlignment = NSTextAlignmentCenter;
    title.font = FONT_16;
    title.textColor = [UIColor whiteColor];
    
    left.frame = CGRectMake(RESIZE_UI(7),20+(44- RESIZE_UI(60/2))/2,RESIZE_UI(60/2),RESIZE_UI(60/2));
    right.frame = CGRectMake(SCREEN_WIDTH-RESIZE_UI(3)-RESIZE_UI(60/1.6), left.top,RESIZE_UI(60/1.6), RESIZE_UI(60/1.6));
    title.frame = CGRectMake(50,(IOS7?20:0),(SCREEN_WIDTH-100),44);
    [self addSubview:left];
    [self addSubview:right];
    [self addSubview:title];
}

- (void)leftButton
{
    if ([delegate respondsToSelector:@selector(leftBtnAction)]) {
        [delegate leftBtnAction];
    }
}
- (void)rightButton
{
    if ([delegate respondsToSelector:@selector(rightBtnAction)]) {
        [delegate rightBtnAction];
    }
}

- (void)dealloc
{
    delegate = nil;
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect
 {
 // Drawing code
 }
 */

@end
